import {
  FooterToolbar,
  PageContainer,
  ProCardTabsProps,
  ProFormInstance,
  ProFormMoney,
  ProFormRadio,
  ProFormTextArea,
  StepsForm,
} from '@ant-design/pro-components';
import {
  ModalForm,
  ProCard,
  ProFormDependency,
  ProFormDigit,
  ProFormGroup,
  ProFormSelect,
  ProFormText,
  ProForm,
} from '@ant-design/pro-components';
import { Button, Card, Divider, InputNumber, Modal, Select, Space, Steps, Tag, message } from 'antd';
import { ReactText, forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
import type { FormDialogProps } from './data';
import type { FormLayout } from 'antd/es/form/Form';
import access from '@/access';
import { useAccess, useLocation } from 'umi';
import { DeleteOutlined, PlusOutlined, SettingFilled } from '@ant-design/icons';
import { calcDeviceList } from '@/services/device/deviceInfo';
import ProList from '@ant-design/pro-list';
import { getG120motorList } from '@/services/drivepara/g120motor';
import { result } from 'lodash';
import { addDeviceInfoExtra, updateDeviceInfoExtra } from '@/services/drivepara/deviceInfoLibEng';
import { getDriveParaLibG120EngByPage } from '@/services/drivepara/driveParaLibG120Eng';
import { getEncoderConfigList } from '@/services/drivepara/encoderConfig';
const { Option } = Select;

const LAYOUT_TYPE_HORIZONTAL = 'horizontal';
const G120Modal: React.FC<FormDialogProps> = (props, uploadRef) => {
  const [visible, setVisible] = useState(false);
  const formRef = useRef<ProFormInstance>();
  const formRefDetail = useRef<ProFormInstance>();
  const [confirmLoading, setConfirmLoading] = useState(false);
  const [initialValues, setInitialValues] = useState({});
  const [controlMode, setControlMode] = useState(0);

  const [formLayoutType, setFormLayoutType] = useState<FormLayout>(LAYOUT_TYPE_HORIZONTAL);
  const [grid, setGrid] = useState(true);
  const access = useAccess();
  const [tab, setTab] = useState('');
  const [tabPosition, setTabPosition] = useState<ProCardTabsProps['tabPosition']>('top');
  const location = useLocation();
  const [vmaxEposLu, setVmaxEposLu] = useState(0);

  const [current, setCurrent] = useState(0);
  const onChange = (value: number) => {
    console.log('onChange:', value);
    if (value === 2) {
      
    } else {
      setCurrent(value);
    }
    
  };

  const [deviceDataSource, setDeviceDataSource] = useState<any[]>([]);
  const actionRef = useRef<ActionType>();
  const [selectedRowKeys, setSelectedRowKeys] = useState<ReactText[]>([]);
  const rowSelection = {
    selectedRowKeys,
    onChange: (keys: ReactText[]) => setSelectedRowKeys(keys),
  };
  const [shaftDataSource, setShaftDataSource] = useState<any[]>([]);
  const [create, setCreate] = useState<Boolean>(false);
  const [deviceCreate, setDeviceCreate] = useState<Boolean>(false);
  const [values, setValues] = useState({});
  const [motorId, setMotorId] = useState(0);


  const g120RowNullData = {
    motorManufacturer: null,
    voltageType: null,
  };


  const encoderRowNullData = {
    encoderManufacturer: null,
    encoderType: null,
  };

  const description = 'This is a description.';


  useEffect(() => {
    setVisible(props.visible);
    setInitialValues(props.initialValues || {});
    setDeviceCreate(props.isCreate || false);
    console.log(props.initialValues.id, "---useEffect---");
    (async () => {
      if (props.initialValues.id !== undefined && props.initialValues.id !== null) {
        console.log(props.initialValues.deviceInfo.id, "---deviceInfoId---");
        const result = await getDriveParaLibG120EngByPage({
          current: 1,
          pageSize: 20,
          deviceInfoId: props.initialValues.deviceInfo.id,
          // deviceInfoExtraId: props.initialValues.deviceInfoExtra.id,
        });
        console.log(result, "---shaftDataSource---");
        setShaftDataSource(result.data.content);
      } else {
        setShaftDataSource([]);
      }
    })();
  }, [props.visible, props.initialValues, props.isCreate]);

  useEffect(() => {
      if (location.query.id !== undefined && location.query.id !== null) {
        formRef.current?.setFieldsValue(props.values);
      }
  }, [props.values]);

  useImperativeHandle(uploadRef, () => {
    // return返回的值就可以被父组件获取到,没返回的值就获取不到
    return {
      // 获取其中的值
      getFieldsValue: () => {
        return formRef.current?.getFieldsValue();
      },
      // 设置值
      setFieldsValue: (value: object) => {
        // console.log(formRef.current);
        // debugger;
        return formRef.current?.setFieldsValue({ shaftName: '测试', hardwareIdentifier: 'hhh' });
      },
      // 重置其中的值
      resetFields: () => {
        return formRef.current?.resetFields();
      },
    };
  });

  const onFinish = async () => {
  }

  return (
    <div>
      <ModalForm
        title={props.title}
        visible={visible}
        formRef={formRef}
        initialValues={initialValues}
        // onFinish={async () => {
        //   setConfirmLoading(true);
        //   await props.onOk();
        //   setConfirmLoading(false);
        //   return true;
        // }}
        onValuesChange={(changeValues) => { }}
        onFinish={async (temp) => {
          if (current === 0) {
            setCurrent(1);
            setDeviceDataSource(temp);
            console.log(temp, "---fields");
          } else if (current === 2) {
            console.log(formRefDetail.current?.getFieldsValue(), "---temp2");
            const detail = formRefDetail.current?.getFieldsValue();
            if (create) {
              detail.id = (Math.random() * 1000000).toFixed(0);
              setShaftDataSource([...shaftDataSource, detail]);
            } else {
              if (detail.id !== null && detail.id !== undefined) {
                for (let i = 0; i < shaftDataSource.length; i++) {
                  if (shaftDataSource[i].id === detail.id) {
                    
                    Object.assign(shaftDataSource[i], detail);
                  }
                }
                setShaftDataSource(shaftDataSource);
              }
            }
            console.log(shaftDataSource, '---shaftDataSource---');
            actionRef.current.reload();
            setCurrent(1);
          } else {
            setConfirmLoading(true);
            let result = null;
            console.log(deviceDataSource.cusDeviceId, '---deviceDataSource[0]---');
            if (deviceCreate) {
              result = await addDeviceInfoExtra({
                vm: deviceDataSource.vm,
                deviceName: deviceDataSource.deviceName,
                memo: deviceDataSource.memo,
                isFromCusDevice: deviceDataSource.isFromCusDevice,
                cusDeviceId: deviceDataSource.cusDeviceId,
                driveParaLibG120EngDtoList: shaftDataSource.map((item) => {
                  return {
                    shaftName: item.shaftName,
                    g120Motor: {
                      motorOrderNum: item.motorOrderNum,
                    },
                  };
                }),
              });
              if (result !== null && result !== undefined) {
                message.success('添加成功');
              }
            } else {
              console.log(initialValues, "---initialValues");
              result = await updateDeviceInfoExtra({
                vm: deviceDataSource.vm,
                deviceName: deviceDataSource.deviceName,
                memo: deviceDataSource.memo,
                isFromCusDevice: initialValues.isFromCusDevice,
                cusDeviceId: initialValues.deviceInfo.id,
                driveParaLibG120EngDtoList: shaftDataSource.map((item) => {
                  delete item.id;
                  return {
                    shaftName: item.shaftName,
                    g120Motor: {
                      motorOrderNum: item.motorOrderNum,
                    },
                  };
                }),
              });
            }
            setConfirmLoading(false);
            setVisible(false);
            await props.onOk();
            return true;
          }
        }}
        // onFinishFailed={() => {
        //   if (current === 0) {
        //     setVisible(false);
        //   } else if (current === 1) {
        //     setCurrent(0);
        //   } else {
        //     setCurrent(1);
        //   }
        // }}
        modalProps={{
          destroyOnClose: true,
          // width: 1000,
          bodyStyle: { height: 500, overflowY: 'scroll' },
          // onCancel: () => props.onCancel(),
          okText: current === 1 ? '提交' : '下一步',
          cancelText: current === 0 ? '取消' : '上一步',
          onCancel: () => {
            if (current === 0) {
              setVisible(false);
            } else if (current === 1) {
              setCurrent(0);
            } else {
              setCurrent(1);
            }
          },
        }}
        layout={formLayoutType}
        grid={grid}
        rowProps={{
          gutter: [16, formLayoutType === 'inline' ? 16 : 0],
        }}
      >
        <Steps
          current={current}
          onChange={onChange}
          items={[
            {
              title: <div style={{ fontSize: '14.5px', fontWeight:'bold' }}>设备信息登记</div>,
            },
            {
              title: <div style={{ fontSize: '14.5px', fontWeight:'bold' }}>轴信息总览</div>,
            },
            {
              title: <div style={{ fontSize: '14.5px', fontWeight:'bold' }}>轴信息登记</div>,
            },
          ]}
        />

        <Divider />

        <ProFormGroup
          key="lib1"
          title="设备信息"
          titleStyle={{ display: 'flex', justifyContent: 'center', fontSize: '16px' }}
          style={{ display: current == 0 ? 'block' : 'none' }}
        >
          <ProFormGroup key="common1-1" style={{ marginTop: '10px' }}>
            <ProFormSelect
              width="md"
              name="isFromCusDevice"
              label="是否来自客户设备信息"
              options={[
                { label: '是', value: 1 },
                { label: '否', value: 0 },
              ]}
              colProps={{ md: 14, xl: 10 }}
              rules={[{ required: true, message: '此项是必填项目' }]}
            />
          </ProFormGroup>

          <ProFormDependency name={['isFromCusDevice']}>
            {({ isFromCusDevice }) => {
              if (isFromCusDevice === 1) {
                return [
                  <ProFormGroup key="common1-2">
                    <ProFormSelect
                      showSearch
                      width="md"
                      name="cusDeviceId"
                      label="设备信息"
                      initialValue={initialValues.id !== null && initialValues.id !== undefined ?
                        initialValues.deviceInfo.identification :
                        null
                      }
                      // rules={[{ required: true, message: '必须选取设备' }]}
                      colProps={{ md: 12, xl: 12 }}
                      debounceTime={1000}
                      request={async (params) => {
                        console.log(params, '--params-');
                        const result = await calcDeviceList({ blurry: params.keyWords });
                        return result.data.map((item) => {
                          return {
                            key: item.id,
                            label: item.identification,
                            value: item.id,
                          };
                        });
                      }}
                      fieldProps={{
                        onChange: () => {
                          formRef.current?.setFieldsValue({
                            isFromCusDevice: 1,
                          });
                          }
                      }}
                    />
                  </ProFormGroup>
                ];
              } else if (isFromCusDevice === 0) {
                return [
                  <ProFormGroup key="common1-2">
                    <ProFormText
                      width="md"
                      name="deviceName"
                      label="设备名称"
                      colProps={{ md: 14, xl: 10 }}
                      rules={[{ required: true, message: '请输入设备名称信息' }]}
                    />
                    <ProFormSelect
                      fieldProps={{
                        //这里使用了select的onChange方法，必须使用这样的写法来进行调用onChange方法
                        onChange: (val, val2) => {
                          console.log(val, val2);
                        },
                      }}
                      colProps={{ md: 12, xl: 6 }}
                      initialValue={1}
                      name="vm"
                      label="行业"
                      options={[
                        { label: '电子', value: 1 },
                        { label: '电池', value: 2 },
                        { label: '物流', value: 3 },
                        { label: '汽车', value: 4 },
                        { label: '太阳能', value: 5 },
                        { label: '增材制造', value: 6 },
                        { label: '包装', value: 7 },
                        { label: '食品饮料', value: 8 },
                        { label: '金属加工', value: 9 },
                        { label: '其他', value: 10 },
                      ]}
                    />
                    <ProFormTextArea
                      colProps={{ span: 22 }}
                      name="memo"
                      label="备注"
                    />
                   </ProFormGroup>
                ];
              } else {}
            }}
          </ProFormDependency>

          {/* <Button
            type="primary"
            icon={<PlusOutlined />}
            style={{position: 'relative', left: '630px'}}
            onClick={() => {
              setCurrent(1);
              setDeviceDataSource(formRef.current?.getFieldsValue());
              console.log(formRef.current?.getFieldsValue(), "---fields");
            }}
          >
            保存
          </Button> */}
        </ProFormGroup>

        <ProFormGroup
          key="lib2"
          title="轴信息总览"
          titleStyle={{ display: 'flex', justifyContent: 'center', fontSize: '16px', marginBottom: '0px' }}
          style={{ display: current == 1 ? 'block' : 'none' }}
        >
          <ProCard colSpan="100%" bodyStyle={{padding: '5px'}}>
            <ProList<any>
              actionRef={actionRef}
              rowKey="id"
              rowSelection={rowSelection}
              dataSource={shaftDataSource}
              toolBarRender={(action, { selectedRows, selectedRowKeys }) => [
                <Button
                  type="primary"
                  icon={<PlusOutlined />}
                  onClick={() => {
                    setCurrent(2);
                    setCreate(true);
                    setValues({});
                  }}
                >
                  新建
                </Button>,
                <Button
                  type="primary"
                  icon={<PlusOutlined />}
                  onClick={() => {
                  }}
                >
                  导入
                </Button>,
                <Button
                  key="button"
                  icon={<DeleteOutlined />}
                  onClick={() => {
                    Modal.confirm({
                      title: '批量删除',
                      content: '是否删除？',
                      okText: '是',
                      cancelText: '否',
                      onOk: async () => {
                        
                      },
                    });
                  }}

                  type="primary"
                >
                  批量删除
                </Button>, 
                // <Button
                //   type="primary"
                //   icon={<PlusOutlined />}
                //   onClick={onFinish}
                // >
                //   提交
                // </Button>,
              ]}
              metas={{
                title: {
                  dataIndex: 'index',
                  valueType: 'index',
                  search: false,
                },

                subTitle: {
                  search: false,
                  render: (text, row) => {
                    return (
                      <Space size={[0,8]} wrap>
                        <Tag color="#5BD8A6">{'驱动选择' + row.isDriveSelected}</Tag>
                        <Tag color="#5BD8A6">{'轴名称' + row.shaftName}</Tag>
                      </Space>
                    )
                  }
                },

                description: {
                  search: false,
                },

                content: {
                  search: false,
                },
                actions:{
                  search: false,
                  render: (text, row) => [
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="link"
                      onClick={() => {
                        setCurrent(2);
                        setValues({ ...row });
                        setCreate(false);
                        console.log({ ...row }, "---...row---");
                      }}
                    >
                      编辑
                    </a>,
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="warning"
                      onClick={() => {
                        let addone = {};
                        shaftDataSource
                          .filter((item) => item.id == row.id)
                          .map((item) => {
                            addone = { ...item };
                          });
                          addone.id = (Math.random() * 1000000).toFixed(0);
                        console.log(addone, '---addOne---');
                        setShaftDataSource([...shaftDataSource, addone]);
                      }}
                    >
                      复制
                    </a>,
                    <a
                      href={row.html_url}
                      target="_blank"
                      rel="noopener noreferrer"
                      key="view"
                      onClick={() => {
                        setShaftDataSource(shaftDataSource.filter((item) => item.id !== row.id));
                      }}
                    >
                      删除
                    </a>,
                  ],

                },
                
              }}
              request={async (params) => {
                return {};
              }}
              pagination={{
                showSizeChanger: true,
              }}

            />
          </ProCard>
        </ProFormGroup>

        <ProForm
          formRef={formRefDetail}
          submitter={false}
          initialValues={values}
        >
          <ProFormGroup
            key="lib3"
            title="轴信息登记"
            titleStyle={{ display: 'flex', justifyContent: 'center', fontSize: '16px', marginBottom: '24px' }}
            style={{ display: current == 2 ? 'block' : 'none' }}
          >
            <ProFormGroup
              key="lib3-1"
              title="基础信息配置"
              titleStyle={{ backgroundColor: '#f0f0f0' }}
              collapsible
            >
              <ProFormText
                hidden={true}
                name="id"
                label="轴信息Id"
                // fieldProps={{
                //   onChange: (child) => {
                //     delete child.rowData.id;
                //     formRefDetail.current?.setFieldsValue({
                //       // ...g120RowNullData,
                //       ...values,
                //     });
                //   },
                // }}
              />
              <ProFormSelect
                width="md"
                name="isDriveSelected"
                label="驱动选择"
                options={[
                  { label: 'FALSE', value: 0 },
                  { label: 'TRUE', value: 1 },
                ]}
                colProps={{ md: 12, xl: 8 }}
              />
              <ProFormText
                width="md"
                name="shaftName"
                label="轴名称"
                colProps={{ md: 12, xl: 8 }}
                rules={[{ required: true, message: '请输入轴名称信息' }]}
              />
              <ProFormSelect
                width="md"
                name="loadType"
                colProps={{ md: 12, xl: 8 }}
                label="负载类型"
                options={[
                  { label: '水平', value: 1 },
                  { label: '旋转', value: 2 },
                  { label: '垂直', value: 3 },
                  { label: '斜坡', value: 4 },
                  { label: '其它', value: 5 },
                ]}
              />
              <ProFormSelect
                width="md"
                name="mechanicalStructure"
                label="机械结构"
                colProps={{ md: 12, xl: 8 }}
                options={[
                  { label: '丝杠', value: 1 },
                  { label: '齿轮齿条', value: 2 },
                  { label: '皮带轮', value: 3 },
                  { label: '圆盘', value: 4 },
                  { label: '辊式带', value: 5 },
                  { label: '链条', value: 6 },
                ]}
              />
              <ProFormSelect
                width="md"
                name="driveType"
                label="驱动类型"
                options={[
                  { label: 'No Selection', value: 0 },
                  { label: 'V90PN', value: 10 },
                  { label: 'S210', value: 20 },
                  { label: 'G120', value: 30 },
                  { label: 'S120-SERVO', value: 40 },
                  { label: 'S120-VECTOR', value: 41 },
                ]}
                colProps={{ md: 12, xl: 8 }}
              />
              <ProFormDigit
                width="md"
                colProps={{ md: 12, xl: 8 }}
                key="CuHardwareIdentifier"
                name="CuHardwareIdentifier"
                label="控制单元硬件标识符"
              />
              <ProFormDigit
                width="md"
                colProps={{ md: 12, xl: 8 }}
                key="hardwareIdentifier"
                name="hardwareIdentifier"
                label="硬件标识符"
              />
              <ProFormText
                width="md"
                name="DriveShaftNum"
                label="驱动轴号"
                colProps={{ md: 12, xl: 8 }}
              />
              <ProFormSelect
                width="md"
                name="IsSlaveSelected"
                label="从轴选择"
                options={[
                  { label: '非从轴', value: 0 },
                  { label: '从轴', value: 1 },
                ]}
                colProps={{ md: 12, xl: 8 }}
              />
            </ProFormGroup>

            <ProFormGroup
              key="lib3-2"
              title="驱动配置"
              titleStyle={{ backgroundColor: '#f0f0f0' }}
              collapsible
            >
              <ProFormGroup>
                <ProFormDigit
                  width="md"
                  colProps={{ md: 12, xl: 8 }}
                  key="supplyVoltage"
                  name="supplyVoltage"
                  label="驱动进线电压 P210"
                />
                <ProFormSelect
                  width="md"
                  name="applicationClass"
                  label="驱动应用级 P96"
                  options={[
                    { label: '专家级', value: 0 },
                    { label: 'SDC', value: 1 },
                    { label: 'DDC', value: 2 },
                  ]}
                  colProps={{ md: 12, xl: 8 }}
                />
                <ProFormDigit
                  width="md"
                  colProps={{ md: 12, xl: 8 }}
                  key="driveDataSetsNum"
                  name="driveDataSetsNum"
                  label="驱动数据组数量 P180"
                />
                <ProFormSelect
                  width="md"
                  name="commTelegram"
                  label="控制报文 P922"
                  colProps={{ md: 12, xl: 8 }}
                  options={[
                    { label: '105', value: 105 },
                    { label: '111', value: 111 },
                    { label: '102', value: 102 },
                    { label: '3', value: 3 },
                    { label: '1', value: 1 },
                  ]}
                />
                <ProFormSelect
                  width="md"
                  name="additionalTelegram"
                  label="附加报文 P8864"
                  colProps={{ md: 12, xl: 8 }}
                  options={[
                    { label: 'None', value: 999 },
                    { label: '750', value: 750 },
                  ]}
                />
                <ProFormSelect
                  width="md"
                  name="controlMode"
                  label="控制模式 P1300"
                  colProps={{ md: 12, xl: 8 }}
                  options={[
                    { label: 'V/F', value: 0 },
                    { label: '无编码器矢量', value: 20 },
                    { label: '编码器速度模式', value: 21 },
                    { label: '基本定位模式', value: 99 },
                  ]}
                />
                <ProFormDigit
                  width="md"
                  colProps={{ md: 12, xl: 8 }}
                  key="currentLimit"
                  name="currentLimit"
                  label="电流限制值 P640 [Arms]"
                />
                <ProFormDigit
                  width="md"
                  colProps={{ md: 12, xl: 8 }}
                  name="refSpeed"
                  label="参考转速 P2000 [rpm]"
                />
                <ProFormDigit
                  width="md"
                  colProps={{ md: 12, xl: 8 }}
                  name="refCurrent"
                  label="参考电流 P2002 [Arms]"
                />
                <ProFormDigit
                  width="md"
                  colProps={{ md: 12, xl: 8 }}
                  name="refTorque"
                  label="参考转矩 P2003 [Nm]"
                />
              </ProFormGroup>
              <ProFormGroup>
                <ProFormDigit
                  width="md"
                  colProps={{ md: 12, xl: 10 }}
                  name="torqueLimUpper"
                  label="转矩限幅上限 P1520 [Nm]"
                />
                <ProFormDigit
                  width="md"
                  colProps={{ md: 12, xl: 10 }}
                  name="torqueLimLower"
                  label="转矩限幅下限 P1521 [Nm]"
                  min={-100000}
                />
              </ProFormGroup>
              <ProFormGroup>
                <ProFormSelect
                  width="md"
                  colProps={{ md: 12, xl: 8 }}
                  name="brake"
                  key="brake"
                  label="抱闸配置 P1215"
                  options={[
                    { label: '无电机抱闸', value: 0 },
                    { label: '电机抱闸同顺序控制', value: 1 },
                    { label: '电机抱闸始终打开', value: 2 },
                    { label: '电机抱闸同顺序控制，通过 BICO 连接', value: 3 },
                  ]}
                />
                <ProFormDigit
                  colProps={{ md: 12, xl: 8 }}
                  width="md"
                  key="tbrakeOpen"
                  name="tbrakeOpen"
                  label="抱闸打开时间 P1216 [ms]"
                />
                <ProFormDigit
                  colProps={{ md: 12, xl: 8 }}
                  width="md"
                  key="tbrakeClose"
                  name="tbrakeClose"
                  label="抱闸闭合时间 P1217 [ms]"
                />
                <ProFormDigit
                  colProps={{ md: 12, xl: 8 }}
                  width="md"
                  key="brakingPower"
                  name="brakingPower"
                  label="制动电阻制动功率 P219 [kW]"
                />
                <ProFormDigit
                  colProps={{ md: 12, xl: 8 }}
                  width="md"
                  key="regenPowerLimit"
                  name="regenPowerLimit"
                  label="再生方式功率极限 P1531 [kW]"
                />
                <ProFormSelect
                  width="md"
                  colProps={{ md: 12, xl: 8 }}
                  name="brakeCtrlDiag"
                  key="brakeCtrlDiag"
                  label="制动控制诊断分析 P1278"
                  options={[
                    { label: '带诊断分析的制动控制', value: 0 },
                    { label: '不带诊断分析的制动控制', value: 1 },
                  ]}
                />
                <ProFormDigit
                  colProps={{ md: 12, xl: 8 }}
                  width="md"
                  key="brakeStartFrequency"
                  name="brakeStartFrequency"
                  label="启动频率 P1351 [%]"
                />
                <ProFormDigit
                  colProps={{ md: 12, xl: 8 }}
                  width="md"
                  key="brakeCtrlDo"
                  name="brakeCtrlDo"
                  label="抱闸控制输出DO"
                />
              </ProFormGroup>
            </ProFormGroup>

            <ProFormGroup
              key="lib3-3"
              title="电机配置"
              titleStyle={{ backgroundColor: '#f0f0f0' }}
              collapsible
            >
              <ProFormSelect
                width="md"
                name="connectionType"
                label="连接类型 P133.0"
                colProps={{ md: 12, xl: 8 }}
                options={[
                  { label: 'Y', value: 0 },
                  { label: 'Δ', value: 1 },
                ]}
              />
              <ProFormSelect
                width="md"
                name="is87Hz"
                label="87Hz运行选择 P133.1"
                colProps={{ md: 12, xl: 8 }}
                options={[
                  { label: '50Hz', value: 0 },
                  { label: '87Hz', value: 1 },
                ]}
              />
              <ProFormSelect
                width="md"
                name="motorOrderNum"
                label="电机订货号"
                colProps={{ md: 12, xl: 8 }}
                debounceTime={1000}
                request={async (params) => {
                  const result = await getG120motorList({ blurry: params.keyWords });
                  result.data.push({ motorOrderNum: '第三方', id: '第三方' });
                  return result.data.map((item) => {
                    return {
                      key: item.id,
                      label: item.motorOrderNum,
                      value: item.motorOrderNum,
                      rowData: item,
                    };
                  });
                }}
                initialValue={initialValues.g120Motor !== null && initialValues.g120Motor !== undefined ?
                  initialValues.g120Motor.motorOrderNum :
                  null
                }
                fieldProps={{
                  onChange: (val, child) => {
                    console.log(child.rowData, '--rowData.id--');
                    delete child.rowData.id;
                    formRefDetail.current?.setFieldsValue({
                      ...g120RowNullData,
                      ...child.rowData,
                    });
                  },
                }}
                rules={[{ required: true, message: '此项是必填项目' }]}
              />
              <ProFormText
                width="md"
                name="motorManufacturer"
                label="电机厂家"
                colProps={{ md: 12, xl: 8 }}
              />
              <ProFormSelect
                width="md"
                name="voltageType"
                label="电压类型"
                options={[
                  { label: '230/400V Δ/Y', value: 0 },
                  { label: '400/690V Δ/Y', value: 1 },
                ]}
                colProps={{ md: 12, xl: 8 }}
              />
            </ProFormGroup>

            <ProFormGroup
              key="lib3-4"
              title="编码器配置"
              titleStyle={{ backgroundColor: '#f0f0f0' }}
              collapsible
            >
              <ProFormGroup
                key="lib3-4-1"
                title="编码器1配置"
              >
                <ProFormSelect
                  width="md"
                  name="encoder1Interface"
                  label="编码器接口 P468[0]"
                  colProps={{ md: 12, xl: 8 }}
                  options={[
                    { label: 'Terminal', value: 1 },
                    { label: 'D-SUB', value: 2 },
                  ]}
                />
                <ProFormDigit
                  colProps={{ md: 12, xl: 8 }}
                  width="md"
                  key="encoder1Revolution"
                  name="encoder1Revolution"
                  label="编码器转数"
                />
                <ProFormDigit
                  colProps={{ md: 12, xl: 8 }}
                  width="md"
                  key="motor1Revolution"
                  name="motor1Revolution"
                  label="电机转数"
                />
                <ProFormSelect
                  width="md"
                  name="encoder1InvertSpeed"
                  label="转速实际值取反 P410[0].00"
                  colProps={{ md: 12, xl: 8 }}
                  options={[
                    { label: 'FALSE', value: 0 },
                    { label: 'TRUE', value: 1 },
                  ]}
                />
                <ProFormSelect
                  width="md"
                  name="encoder1InvertPos"
                  label="位置实际值取反 P410[0].01"
                  colProps={{ md: 12, xl: 8 }}
                  options={[
                    { label: 'FALSE', value: 0 },
                    { label: 'TRUE', value: 1 },
                  ]}
                />
                <ProFormSelect
                  width="md"
                  name="encoder1Num"
                  label="编码器型号"
                  colProps={{ md: 12, xl: 8 }}
                  debounceTime={1000}
                  request={async (params) => {
                    const result = await getEncoderConfigList({ blurry: params.keyWords });
                    result.data.push({ encoderNum: '第三方', id: '第三方' });
                    return result.data.map((item) => {
                      return {
                        key: item.id,
                        label: item.encoderNum,
                        value: item.encoderNum,
                        rowData: item,
                      };
                    });
                  }}
                  initialValue={initialValues.encoder1Info !== null && initialValues.encoder1Info !== undefined ?
                    initialValues.encoder1Info.encoderNum :
                    null
                  }
                  fieldProps={{
                    onChange: (val, child) => {
                      console.log(child.rowData, '--rowData.id--');
                      delete child.rowData.id;
                      formRefDetail.current?.setFieldsValue({
                        ...encoderRowNullData,
                        ...child.rowData,
                      });
                    },
                  }}
                  // rules={[{ required: true, message: '此项是必填项目' }]}
                />
                <ProFormText
                  width="md"
                  name="encoderManufacturer"
                  label="编码器厂家"
                  colProps={{ md: 12, xl: 8 }}
                />
                <ProFormSelect
                  width="md"
                  name="encoderType"
                  label="编码器类型"
                  options={[
                    { label: '1024HTL A/B R', value: '3001' },
                    { label: '1024HTL A/B', value: '3005' },
                    { label: 'User-defined', value: '9999' },
                  ]}
                  colProps={{ md: 12, xl: 8 }}
                />
              </ProFormGroup>
              <ProFormGroup
                key="lib3-4-2"
                title="编码器2配置"
              >
                <ProFormSelect
                  width="md"
                  name="IsEncoder2Selected"
                  label="编码器2选择"
                  colProps={{ md: 12, xl: 8 }}
                  options={[
                    { label: '编码器2未选择', value: 0 },
                    { label: '编码器2已选择', value: 1 },
                  ]}
                />
                <ProFormSelect
                  width="md"
                  name="encoder1Interface"
                  label="编码器接口 P468[1]"
                  colProps={{ md: 12, xl: 8 }}
                  options={[
                    { label: 'Terminal', value: 1 },
                    { label: 'D-SUB', value: 2 },
                  ]}
                />
                <ProFormDigit
                  colProps={{ md: 12, xl: 8 }}
                  width="md"
                  key="encoder2Revolution"
                  name="encoder2Revolution"
                  label="编码器转数"
                />
                <ProFormDigit
                  colProps={{ md: 12, xl: 8 }}
                  width="md"
                  key="motor2Revolution"
                  name="motor2Revolution"
                  label="电机转数"
                />
                <ProFormSelect
                  width="md"
                  name="encoder1InvertSpeed"
                  label="转速实际值取反 P410[1].00"
                  colProps={{ md: 12, xl: 8 }}
                  options={[
                    { label: 'FALSE', value: 0 },
                    { label: 'TRUE', value: 1 },
                  ]}
                />
                <ProFormSelect
                  width="md"
                  name="encoder1InvertPos"
                  label="位置实际值取反 P410[1].01"
                  colProps={{ md: 12, xl: 8 }}
                  options={[
                    { label: 'FALSE', value: 0 },
                    { label: 'TRUE', value: 1 },
                  ]}
                />
                <ProFormSelect
                  width="md"
                  name="encoder2Num"
                  label="编码器型号"
                  colProps={{ md: 12, xl: 8 }}
                  debounceTime={1000}
                  request={async (params) => {
                    const result = await getEncoderConfigList({ blurry: params.keyWords });
                    result.data.push({ encoderNum: '第三方', id: '第三方' });
                    return result.data.map((item) => {
                      return {
                        key: item.id,
                        label: item.encoderNum,
                        value: item.encoderNum,
                        rowData: item,
                      };
                    });
                  }}
                  initialValue={initialValues.encoder1Info !== null && initialValues.encoder1Info !== undefined ?
                    initialValues.encoder1Info.encoderNum :
                    null
                  }
                  fieldProps={{
                    onChange: (val, child) => {
                      console.log(child.rowData, '--rowData.id--');
                      delete child.rowData.id;
                      formRefDetail.current?.setFieldsValue({
                        ...encoderRowNullData,
                        ...child.rowData,
                      });
                    },
                  }}
                  // rules={[{ required: true, message: '此项是必填项目' }]}
                />
                <ProFormText
                  width="md"
                  name="encoderManufacturer"
                  label="编码器厂家"
                  colProps={{ md: 12, xl: 8 }}
                />
                <ProFormSelect
                  width="md"
                  name="encoderType"
                  label="编码器类型"
                  options={[
                    { label: '1024HTL A/B R', value: '3001' },
                    { label: '1024HTL A/B', value: '3005' },
                    { label: 'User-defined', value: '9999' },
                  ]}
                  colProps={{ md: 12, xl: 8 }}
                />
              </ProFormGroup>
            </ProFormGroup>

            <ProFormGroup
              key="lib3-5"
              title="工艺参数"
              titleStyle={{ backgroundColor: '#f0f0f0' }}
              collapsible
            >

            </ProFormGroup>

            {/* <Button
              key="button"
              icon={<PlusOutlined />}
              type="primary"
              onClick={() => {
                const detail = formRef.current?.getFieldsValue();
                if (create) {
                  detail.id = (Math.random() * 1000000).toFixed(0);
                  setShaftDataSource([...shaftDataSource, detail]);
                } else {
                  if (detail.id !== null && detail.id !== undefined) {
                    for (let i = 0; i < shaftDataSource.length; i++) {
                      if (shaftDataSource[i].id === detail.id) {
                        Object.assign(shaftDataSource[i], detail);
                      }
                    }
                    setShaftDataSource(shaftDataSource);
                  }
                }
                console.log(shaftDataSource, '---shaftDataSource---');
                actionRef.current.reload();
                setCurrent(1);
              }}
            >
              保存至总览
            </Button> */}
          </ProFormGroup>
        </ProForm>


      </ModalForm>
    </div>
  );

};
const G120LibEngCommon = forwardRef<unknown, FormDialogProps>(G120Modal);

export default G120LibEngCommon;
